<?php
include_once 'admin_check.php'; 
$is_show = array('隐藏','显示');
$eid = isset($_GET['eid']) && !empty($_GET['eid'])?$_GET['eid']:'';
$data = getOne('message',"msg_id = {$eid}");

if($_POST){
  $data['msg_is_show'] = $_POST['is_show'];
  $id = isset($_POST['id']) && !empty($_POST['id'])?$_POST['id']:'';
  if($eid){ //如果是编辑
    if($id){
      $r = update('message',$data,"msg_id = {$id}");
      if($r){
        show_msg('更新成功');
      }else{
        show_msg('更新失败');
      }
    }
  }
}
?>
<?php include_once"header.php" ?>
    <div id="topbar" class="affix">
      <ol class="breadcrumb">
        <li><a href="index.php"><span class="glyphicon glyphicon-home"></span></a></li>
        <li class="active"><?php echo $eid?'
        编辑':'添加'?>留言</li>
      </ol>
    </div>
    <div class="container">

	 <div class="row">
        <div class="col-md-10 col-lg-11 center-column">
        <form action="" method="post" class="cmxform">
        	<div class="panel">
            <div class="panel-heading">
              <div class="panel-title"><?php echo $eid?'
        编辑':'添加'?>留言</div>
              <div class="panel-btns pull-right margin-left">
              <a href="news_list.php" class="btn btn-default btn-gradient dropdown-toggle"><span class="glyphicon glyphicon-chevron-left"></span></a>
            	  </div>
            </div>
            <div class="panel-body">
            	  <div class="col-md-7">
                  <!-- 如果是编辑页面则会post一个ID，如果是添加则这个ID为空 -->
                  <input type="hidden" name="id" value="<?php echo $data['msg_id']?>">

                  <div class="form-group">
                    <div class="input-group"> 
                      <p class="lead">留言内容：</p>
                      <p><?php echo $data['msg_content']?></p>
                    </div>
                  </div>

                  <div class="form-group">
                    <div class="input-group"> <span class="input-group-addon">是否显示</span>
                      <select class="form-control" name='is_show'>
                        <?php foreach ($is_show as $key => $value){ ?>
                         <option value="<?php echo $key ?>" <?php echo !empty($data['msg_is_show']) && $data['msg_is_show'] == $key ? 'selected' : '' ?>><?php echo $value ?></option>
                        <?php } ?>
                      </select>
                    </div>
                  </div>
                </div>
                <div class="col-md-7">
	                <div class="form-group">
	                  <input type="submit" value="提交" class="submit btn btn-blue">
	                </div>
                </div>
            </div>
          </div>
          </form>
        </div>
    </div>
  </section>
  <!-- End: Content --> 
</div>

</body>

</html>